package com.whately.core.base.config.aspect;

import com.whately.core.base.constant.DebugSwitcher;
import com.whately.core.base.selfconfig.SelfDefineConfigWhLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Configuration;

/**
 * 日志log拦截器
 * 记录入口的日志信息
 * 打印描述信息及入参
 *
 *
 * 兼容一起的老项目，因为老项目本身已经加了log日志，
 * 通过配置参数，不需要拦截Controller和Service日志
 */
@Aspect
@Configuration
@ConditionalOnExpression("${myconfig.whlog.enable:true} && ${myconfig.whlog.pointCutCtrlSrv:true}==false")
@Slf4j
public class WhLogOnlyAnnoAspect {

    @Autowired
    private DebugSwitcher debugSwitcher;

    @Autowired
    private SelfDefineConfigWhLog selfDefineConfigWhLog;


    @Pointcut("@annotation(com.whately.core.base.annotation.WhLog)")
    public void pointCut() {

    }

    @Around(value = "pointCut()")
    public Object process(ProceedingJoinPoint point) throws Throwable {
        return WhLogAllAspect.dealLogAspect(point,debugSwitcher,selfDefineConfigWhLog);
    }





}
